package com.ruoyi.web.controller.cms;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.domain.CrmMeetRoom;
import com.ruoyi.cms.service.ICrmMeetRoomService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 会议室Controller
 * 
 * @author hct
 * @date 2022-10-06
 */
@RestController
@RequestMapping("/cms/room")
public class CrmMeetRoomController extends BaseController
{
    @Autowired
    private ICrmMeetRoomService crmMeetRoomService;

    /**
     * 查询会议室列表
     */
    @PreAuthorize("@ss.hasPermi('cms:room:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmMeetRoom crmMeetRoom)
    {
        startPage();
        List<CrmMeetRoom> list = crmMeetRoomService.selectCrmMeetRoomList(crmMeetRoom);
        return getDataTable(list);
    }

    /**
     * 导出会议室列表
     */
    @PreAuthorize("@ss.hasPermi('cms:room:export')")
    @Log(title = "会议室", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CrmMeetRoom crmMeetRoom)
    {
        List<CrmMeetRoom> list = crmMeetRoomService.selectCrmMeetRoomList(crmMeetRoom);
        ExcelUtil<CrmMeetRoom> util = new ExcelUtil<CrmMeetRoom>(CrmMeetRoom.class);
        util.exportExcel(response, list, "会议室数据");
    }

    /**
     * 获取会议室详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:room:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmMeetRoomService.selectCrmMeetRoomById(id));
    }

    /**
     * 新增会议室
     */
    @PreAuthorize("@ss.hasPermi('cms:room:add')")
    @Log(title = "会议室", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmMeetRoom crmMeetRoom)
    {
        return toAjax(crmMeetRoomService.insertCrmMeetRoom(crmMeetRoom));
    }

    /**
     * 修改会议室
     */
    @PreAuthorize("@ss.hasPermi('cms:room:edit')")
    @Log(title = "会议室", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmMeetRoom crmMeetRoom)
    {
        return toAjax(crmMeetRoomService.updateCrmMeetRoom(crmMeetRoom));
    }

    /**
     * 删除会议室
     */
    @PreAuthorize("@ss.hasPermi('cms:room:remove')")
    @Log(title = "会议室", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmMeetRoomService.deleteCrmMeetRoomByIds(ids));
    }
}
